'use strict';
exports.main = async (event, context) => {
	const db = uniCloud.database();
	
	const dbcmd = db.command;
	
	let params = event.body ? JSON.parse(event.body) : event
	// 客户端上传的参数
	console.log('params : ', params)
	
	let lastId = params.lastId || 0;
	let pageSize = params.pageSize || 10;
	
	let opt = {};
	
	// 查询_id大于lastId的数据
	if(lastId)opt._id = dbcmd.gt(lastId)
	
	console.log("lastId",lastId)
	console.log("pageSize",pageSize)
	console.log("opt",opt)
	
	let res = await db.collection("books").where(opt).limit(pageSize).get()
	
	//返回数据给客户端
	return res
};
